//package com.tsoj.tsojquestionservice.controller;
//
//import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
//
//import com.tsoj.common.BaseResponse;
//import com.tsoj.common.ErrorCode;
//import com.tsoj.common.ResultUtils;
//import com.tsoj.context.ThreadLocalContext;
//import com.tsoj.exception.BusinessException;
//import com.tsoj.model.dto.questionSubmit.QuestionSubmitAddDto;
//import com.tsoj.model.dto.questionSubmit.QuestionSubmitQueryDto;
//import com.tsoj.model.po.QuestionSubmit;
//import com.tsoj.model.vo.QuestionSubmitVO;
//import com.tsoj.propertise.MaxPageSizePropertise;
//import com.tsoj.tsojquestionservice.service.QuestionsubmitService;
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiOperation;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.bind.annotation.*;
//
//import javax.servlet.http.HttpServletRequest;
//
///**
// * 题目提交接口
// */
//@RestController
//@RequestMapping("/question_submit")
//@Api(tags = "题目提交接口")
//public class QuestionSubmitController {
//
//    @Autowired
//    private QuestionsubmitService questionsubmitService;
//    @Autowired
//    private UserService userService;
//    /**
//     * 提交题目
//     *
//     * @param questionSubmitAddRequest
//     * @return 提交记录的 id
//     */
//    @ApiOperation(value = "提交题目")
//    @PostMapping("/do")
//    public BaseResponse<Long> doQuestionSubmit(@RequestBody QuestionSubmitAddDto questionSubmitAddRequest) {
//        if (questionSubmitAddRequest == null || questionSubmitAddRequest.getQuestionId() <= 0) {
//            throw new BusinessException(ErrorCode.PARAMS_ERROR);
//        }
//        // 登录才能点赞
//        long id = ThreadLocalContext.getUserId();
//        long questionSubmitId = questionsubmitService.doQuestionSubmit(questionSubmitAddRequest, id);
//        return ResultUtils.success(questionSubmitId);
//    }
//    @Autowired
//    private MaxPageSizePropertise maxPageSizePropertise;
//    /**
//     * 题目提交列表分页获取（仅管理员） todo 待优化看是否要做鉴权处理
//     */
//    @ApiOperation(value = "题目提交列表分页获取 普通用户")
//    @PostMapping("/list/page")
//    public BaseResponse<Page<QuestionSubmitVO>> listPageQuestionSubmit(@RequestBody QuestionSubmitQueryDto questionSubmitQueryDto){
//
//        long current = questionSubmitQueryDto.getCurrent();//当前页码
//        long size = questionSubmitQueryDto.getPageSize();//分页大小
//
//        if(size > maxPageSizePropertise.getMaxPageSize()){
//            throw new BusinessException(ErrorCode.PARAMS_ERROR, "参数错误");
//        }
//        Page<QuestionSubmit> page = questionsubmitService.page(new Page<>(current,size),
//                questionsubmitService.getQueryWrapper(questionSubmitQueryDto));
//        //设置用户只能看到自己的代码
//        Long userId = ThreadLocalContext.getUserId();
//        boolean admin = userService.isAdmin(userId);
//        //做脱敏处理
//        Page<QuestionSubmitVO> pageQuestionSubmitVO = questionsubmitService.getQuestionSubmitVOList(page,userId);
//        return ResultUtils.success(pageQuestionSubmitVO);
//    }
//    @ApiOperation(value = "题目提交列表分页获取 管理员可用")
//    @GetMapping("/list/page/admin")
//    public BaseResponse<Page<QuestionSubmit>> listPageQuestionSubmit(@RequestBody QuestionSubmitQueryDto questionSubmitQueryDto, HttpServletRequest request){
//        if(questionSubmitQueryDto == null){
//            throw new BusinessException(ErrorCode.PARAMS_ERROR);
//        }
//        long current = questionSubmitQueryDto.getCurrent();//当前页码
//        long size = questionSubmitQueryDto.getPageSize();//分页大小
//
//        if(size > maxPageSizePropertise.getMaxPageSize()){
//            throw new BusinessException(ErrorCode.PARAMS_ERROR, "参数错误");
//        }
//        //管理员校验
//        Long userId = ThreadLocalContext.getUserId();
//        if(!userService.isAdmin(userId)){
//            throw new BusinessException(ErrorCode.NO_AUTH_ERROR);
//        }
//        Page<QuestionSubmit> page = questionsubmitService.page(new Page<>(current,size),
//                questionsubmitService.getQueryWrapper(questionSubmitQueryDto));
//        return ResultUtils.success(page);
//    }
//
//}
